package containersInDepth;

public class Test {
    static int MAXIMUM_CAPACITY = 1 << 30;
    public static void main(String arg[]){
//        System.out.println(Integer.highestOneBit(15));
//        System.out.println(roundUpToPowerOf222(33));
        System.out.println((String)null+"asdfadsfadf");
    }
    public static int roundUpToPowerOf222(int number){
        int rounded;
        if(number>=MAXIMUM_CAPACITY){
            rounded = MAXIMUM_CAPACITY;
        }else{
            rounded = Integer.highestOneBit(number);
            if(rounded!=0){
                if(Integer.bitCount(number) > 1){
                    rounded = rounded << 1;
                }else{
                    rounded = rounded;
                }
            }else{
                rounded = 1;
            }
        }
        return rounded;
    }
    public static int roundUpToPowerOf2(int number){
        int rounded = number >= MAXIMUM_CAPACITY
                ? MAXIMUM_CAPACITY
                : (rounded = Integer.highestOneBit(number)) != 0
                    ? (Integer.bitCount(number) > 1) ? rounded << 1 : rounded
                    : 1;
        return rounded;
    }
}
